'use server';
import { formatFindParams } from '@/pao/server/serverPrisma';
import { PrismaClient, Capability } from '@/data/prisma';

const prisma = new PrismaClient()

export async function query(filter: Record<string, any>
	, sorter: Record<string, any>
	, pageSize: number = 50
	, pageIndex: number = 1
	, columnFilterTypes: Record<string, string> = {}): Promise<{ rows: Capability[]; total: number; }> {
	const subjects = await prisma.capability.findMany(formatFindParams(filter, sorter, pageSize, pageIndex, columnFilterTypes))
	return { rows: subjects as unknown as Capability[], total: subjects.length }
}

export async function deleteRow(row: Capability) {
	await prisma.capability.delete({ where: { id: row.id } })
}

export async function editRow(row: Capability) {
	await prisma.capability.update({ where: { id: row.id }, data: row })
}

export async function addRow(row: Capability) {
	await prisma.capability.create({ data: row })
}